﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using HRProject.Code.DAO;
using HRProject.Code.Common;
using System.Collections.Generic;
using HRProject.Code.DTO;

namespace HRProject.Task
{
    public partial class RemoveTaskType : System.Web.UI.Page
    {
        private Guid taskTypeId = Guid.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string id = Request.Params["id"];
                try
                {
                    taskTypeId = new Guid(id);
                }
                catch (Exception exp)
                {
                    Console.Out.Write(exp.StackTrace);
                    taskTypeId = Guid.Empty;
                }
                TaskTypeDAO dao = new TaskTypeDAO();
                BLTaskType filter = new BLTaskType();
                filter.Id = taskTypeId;
                filter.Name = string.Empty;
                filter.Parent = new BLTaskType();
                filter.Parent.Id = Guid.Empty;
                List<BLTaskType> taskTypes = dao.search(filter);
                if (taskTypes.Count > 0)
                {
                    hdfId.Value = taskTypeId.ToString();
                    tbxName.Text = taskTypes[0].Name;
                    tbxParent.Text = taskTypes[0].Parent.Name;
                }
            }
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            if (!BLAuthentication.IsRemoveAllowed)
            {
                lblError.Text = ContentProvider.GetMessage("NotAuthorized");
                return;
            }

            BLTaskType taskType = new BLTaskType();
            try
            {
                taskTypeId = new Guid(hdfId.Value);
            }
            catch (Exception exp)
            {
                Console.Out.Write(exp.StackTrace);
                taskTypeId = Guid.Empty;
            }
            taskType.Id = taskTypeId;
            taskType.Name = tbxName.Text;
            taskType.DataSignature = 0;

            TaskTypeDAO dao = new TaskTypeDAO();
            dao.delete(taskType);

            Util.CloseFrame(Response);
        }
    }
}
